import {createStore} from'vuex'
import {getBanner} from "../api";

const store = createStore({
    state:{
        user:null,
        singingMusic:'',
        musicList:[],
        souSuoLiShi:[],
        loginStatus:'',
        url:''
    },
    getters:{

    },
    mutations:{
        login(state,user){
            state.user=user
        },
        liShiQingKong(state){
            state.souSuoLiShi=[]
            console.log(state.souSuoLiShi)
        },
        liShi(state,souSuo){
            if(/^ [\s]*$/.test(souSuo))return false
            if(!state.souSuoLiShi.includes((souSuo.trim())))state.souSuoLiShi.unshift((souSuo))
        },
        boFang(state,url){
            state.url=url
            console.log(state.url)
        }
    },
    actions:{
        login(context,user){
            getBanner(`/login/cellphone?phone=${user.account}&password=${user.password}`)
                .then(response=>{
                        console.log(response.data)
                        context.commit('login',response.data)
                    })
        },
        liShi(context,souSuo){
            console.log(souSuo)
            context.commit('liShi',souSuo)
        },
        boFang(context,url){
            console.log(url)
            context.commit('boFang',url)
        }
    }
})

export default store